package org.dbstar.scheduler.control.db.operate;

import java.sql.Types;

import org.dbstar.scheduler.beans.OperateType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;


/**
 * 插入一条操作记录
 * 
 * @author 代波
 * @since 1.0.0
 * @version 1.0.0
 * @date 2012-6-5
 */
public class OperateInsert extends SimpleJdbcInsert {
	public OperateInsert(JdbcTemplate jdbcTemplate) {
		super(jdbcTemplate);
		withTableName("SCHD_OPERATE");
		usingColumns("OPERATOR", "OPERATE", "PARAMETER", "OPERATE_TIME");
		usingGeneratedKeyColumns("ID");
	}

	public int insertOperate(String operator, OperateType operate, String parameter) {
		MapSqlParameterSource source = new MapSqlParameterSource();
		source.addValue("OPERATOR", operator, Types.VARCHAR);
		source.addValue("OPERATE", operate.name(), Types.VARCHAR);
		source.addValue("PARAMETER", parameter, Types.VARCHAR);
		source.addValue("OPERATE_TIME", System.currentTimeMillis(), Types.BIGINT);
		return super.executeAndReturnKey(source).intValue();
	}
}
